package com.wanhelibs.custom_view.animate;

import android.content.Context;
import android.view.animation.AnimationUtils;

import com.wanhe.base.model.disgn.Event;
import com.wanhe.base.model.disgn.ViewEvent;
import com.wanhe.viewconf.views.child.MealBookChildItemView;
import com.wanhe.viewconf.views.child.interfaces.IBindingViewFunc;
import com.wanhelibs.R;

import java.util.HashMap;
import java.util.Map;

/**
 * File Name:MealBookAnimateBinder.java<br/>
 * Package Name:com.wanhelibs.custom_view.animate<br/>
 * Date:2017/7/27 19:54<br/>
 * author:chendeji<br/>
 * desc: 动画绑定<br/>
 * Copyright (c) 2017/7/27, 781571323@qq.com All Rights Reserved.
 *
 */
public class MealBookAnimateBinder extends MealBookChildItemView implements IBindingViewFunc{

    private static Map<String, Integer> animateResMap = new HashMap<>();
    static {
        //入场动画
        animateResMap.put("leftIn", R.anim.anim_left_in);
        animateResMap.put("rightIn", R.anim.anim_right_in);
        animateResMap.put("upIn", R.anim.anim_up_in);
        animateResMap.put("downIn", R.anim.anim_down_in);
        animateResMap.put("fadeIn", R.anim.anim_fade_in);

        //出场动画
        animateResMap.put("leftOut", R.anim.anim_left_out);
        animateResMap.put("rightOut", R.anim.anim_right_out);
        animateResMap.put("upOut", R.anim.anim_up_out);
        animateResMap.put("downOut", R.anim.anim_down_out);
        animateResMap.put("fadeOut", R.anim.anim_fade_out);
    }



    public MealBookAnimateBinder(Context context) {
        super(context);
    }

    @Override
    public void bind(Event event, ViewEvent.Coor coor) {
        String actionIn = this.getItem().getActionIn();
        int animateResIn = animateResMap.get(actionIn);
        String actionOut = this.getItem().getActionOut();
        int animateResOut = animateResMap.get(actionOut);

        /**
         * 回向绑定，将动画资源属性回传给需要绑定动画的控件
         * @author 陈德基
         * @time 2017/8/3 14:16
         */
        int[] animationSet = new int[]{animateResIn, animateResOut};
        event.getArgs().setCusObj(animateResIn);
        int fromCid = event.fromCid;
        event.fromCid = event.getCid();
        event.setCid(fromCid);
        event.getArgs().setCusObj(animationSet);
        sendEvent(event);

    }
}
